package com.cms.service;



import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cms.dao.UserDao;
import com.cms.entity.User;
import com.cms.util.PasswordUtil;

/**
*@author:gang
*@version:
**/
@Service
public class UserService {
	
	@Autowired
	private UserDao userDao;
	
	@Autowired
	private PasswordUtil passwordUtil;
	
	public User addUser(String name,String password,String email,String country){
		User user = new User();
		user.setUserPassword(password);
		user.setUserName(name);
		user.setCountry(country);
		user.setEmail(email);
		Date date = new Date();
		user.setDate(date);
		passwordUtil.encryptPassword(user);
		userDao.addUser(user);
		return user;
	}

	public User getUserByName(String name) {
		// TODO Auto-generated method stub
		User user = new User();
		user = userDao.getUserByName(name);
		return user;
	}
	
	public String getPasswordByUtil(User user,String password){
		String hashPassword = passwordUtil.returnPassword(user,password);
		return hashPassword;
	} 
	

}
